package com.burgeon.backend.SHOP.rest.recharger;
/**
 * 查询vip余额
 */

import com.burgeon.backend.Rest.base.RESTBase;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class FindVipBalance extends RESTBase {



    private String ip;
    private String account;
    private String password;

    public FindVipBalance(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     * @return
     */

    public String getData(String phone) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(phone),url);
        System.err.println(str);
        String code = new JSONArray(str).getJSONObject(0).getString("code");
        String message = new JSONArray(str).getJSONObject(0).getString("message");
        if (!"0".equals(code)){
            throw new Exception(message);
        }
        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");


        return jsonArray.getJSONArray(0).getString(0);
    }

    private MultiValueMap Data(String phone) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("'AMOUNT'");


        params.put("columns", columns);
        params.put("table", "FA_VIPACC");//表名

        HashMap paramss = new HashMap();
        String ac = "'="+ phone+"'";
        paramss.put("column", "'C_VIP_ID;CARDNO'");
        paramss.put("condition", ac);
        params.put("params", paramss);

        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) {
        FindVipBalance getRetailByVip = new FindVipBalance("47.92.53.75:90", "dy@xcx.com", "123");
        try {
            System.err.println(getRetailByVip.getData("17732141036"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
